package com.kaoqin.code.sys;

import org.springframework.beans.factory.config.PropertyPlaceholderConfigurer;

import com.kaoqin.code.util.DESUtils;

public class EncryptPropertyPlaceholderConfigurer extends
		PropertyPlaceholderConfigurer {
	private String[] encryptPropNames = {"jdbc.username","jdbc.password"};

	@Override
	protected String convertProperty(String propertyName, String propertyValue) {
		// 如果在加密属性名单中发现该属性
		if (isEncryptProp(propertyName)) {
			String decryptValue = "";
			try {
				DESUtils des = new DESUtils("svipit.com");
				decryptValue = des.decrypt(propertyValue);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return decryptValue;
		} else {
			return propertyValue;
		}

	}
	private boolean isEncryptProp(String propertyName) {
		for (String encryptName : encryptPropNames) {
			if (encryptName.equals(propertyName)) {
				return true;
			}
		}
		return false;
	}
}
